﻿using BLL;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.SelfUtils;

namespace Web
{
    public partial class UserIndex : System.Web.UI.Page
    {
        Pager pager;
        protected void Page_Load(object sender, EventArgs e)
        {
            pager = ViewState["pager"] as Pager;
            if (!IsPostBack)
            {
                Pager pager1 = new Pager();
                ViewState["pager"] = pager1;//页面重新加载后更新分页对象

                repeater1Add(pager1);
            }
        }
        //首页
        protected void Button3_Click(object sender, EventArgs e)
        {
            pager.FirstPage();
            repeater1Add(pager);
        }
        //上一页
        protected void Button4_Click(object sender, EventArgs e)
        {
            pager.PrevPage();
            repeater1Add(pager);
        }
        //指定页
        protected void Button7_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.Trim() != "")
            {
                int i = int.Parse(TextBox1.Text.Trim());
                pager.ToPage(i);
                repeater1Add(pager);
            }
        }
        //下一页
        protected void Button5_Click(object sender, EventArgs e)
        {
            pager.NextPage();
            repeater1Add(pager);
        }
        //尾页
        protected void Button6_Click(object sender, EventArgs e)
        {
            Pager pager = ViewState["pager"] as Pager;
            pager.LastPage();
            repeater1Add(pager);
        }
        void repeater1Add(Pager pager)
        {
            GoodsBLL gb=new GoodsBLL();
            pager.Count = gb.selectAll().Count;

            Label1.Text = string.Format("{0}/{1}", pager.PageIndex, pager.PageCount);
            Repeater1.DataSource = GoodsBLL.selectBytime(pager.PageSize, pager.PageIndex);
            Repeater1.DataBind();
        }
    }
}